#!/usr/bin/env sh

# 主机目录 => 容器目录
# HTML_PATH => /var/www/html
# PHP_PATH => /data

# 切换到项目目录（容器目录）
LARAVEL_PATH=/var/www/html/laravel8
cd ${LARAVEL_PATH}

if [ ! -f .env ]; then
  echo "安装 laravel8 ..."
  composer install --ignore-platform-reqs

  # 复制配置文件
  \cp .env.example .env

  echo "更新配置文件..."
  . /data/install.conf
  # Server
  sed -i "s|APP_DOMAIN=.*|APP_DOMAIN=${SERVER_IP}|g;s|SERVER_IP=.*|SERVER_IP=${SERVER_IP}|g;s|NETWORK_UUID=.*|NETWORK_UUID=${NETWORK_UUID}|g;" .env
  # Mysql
  sed -i "s|DB_HOST=.*|DB_HOST=${DB_HOST}|g;s|DB_PORT=.*|DB_PORT=${DB_PORT}|g;s|DB_DATABASE=.*|DB_DATABASE=${DB_DATABASE}|g;s|DB_USERNAME=.*|DB_USERNAME=${DB_USERNAME}|g;s|DB_PASSWORD=.*|DB_PASSWORD=${DB_PASSWORD}|g;" .env
  # Redis
  sed -i "s|REDIS_URL=.*|REDIS_URL=tcp://${REDIS_HOST}:${REDIS_PORT}|g;s|REDIS_HOST=.*|REDIS_HOST=${REDIS_HOST}|g;s|REDIS_PORT=.*|REDIS_PORT=${REDIS_PORT}|g;" .env
  # Theme
  sed -i "s|THEME_VERSION=.*|THEME_VERSION=${THEME_VERSION}|g;" .env

  # 执行安装脚本
  ./init.sh
fi


# 执行更新
# chmod +x /data/sh/laravel8/migrate.sh && 
./update.sh